package com.hotelsystem.reservations.reservations;

import java.util.ArrayList;
import java.util.Date;

import com.hotelsystem.reservations.hotels.Hotel;
import com.hotelsystem.reservations.persons.Client;
import com.hotelsystem.reservations.rooms.Room;
import com.hotelsystem.reservations.rooms.RoomTypesEnum;

public class ReservationDetails {

	private RoomTypesEnum roomType;
	private Boolean hasBreakfast;
	private Boolean hasDinner;
	private Boolean isSmokersFree;
	private ReservationStatusEnum reservationStatus;
	private ArrayList <Client> clientList;

	public ReservationDetails() {
		super();
	}

	public ReservationDetails(RoomTypesEnum roomType, boolean hasBreakfast, boolean hasDinner, boolean isSmokersFree,
			ReservationStatusEnum reservationStatus, ArrayList <Client> clientList) {
		super();
		this.roomType = roomType;
		this.hasBreakfast = hasBreakfast;
		this.hasDinner = hasDinner;
		this.isSmokersFree = isSmokersFree;
		this.reservationStatus = reservationStatus;
		this.clientList = clientList;
	}

	public RoomTypesEnum getRoomType() {
		return roomType;
	}

	public void setRoomType(RoomTypesEnum roomType) {
		this.roomType = roomType;
	}

	public Boolean isHasBreakfast() {
		return hasBreakfast;
	}

	public void setHasBreakfast(Boolean hasBreakfast) {
		this.hasBreakfast = hasBreakfast;
	}

	public Boolean isHasDinner() {
		return hasDinner;
	}

	public void setHasDinner(Boolean hasDinner) {
		this.hasDinner = hasDinner;
	}

	public Boolean isSmokersFree() {
		return isSmokersFree;
	}

	public void setSmokersFree(Boolean isSmokersFree) {
		this.isSmokersFree = isSmokersFree;
	}

	public ReservationStatusEnum getReservationStatus() {
		return reservationStatus;
	}

	public void setReservationStatus(ReservationStatusEnum reservationStatus) {
		this.reservationStatus = reservationStatus;
	}

	public ArrayList<Client> getClientList() {
		return clientList;
	}

	public void setClientList(ArrayList<Client> clientList) {
		this.clientList = clientList;
	}

	public Room getRoomByDetails(ArrayList<Room> rooms, Date startDate, Date endDate,
			ArrayList<Reservation> reservations) {

		for (Room room : rooms) {

			if (!room.isRoomFree(startDate, endDate, reservations)) {
				continue;
			}

			if (!roomType.getName().equals(room.getRoomType().getName())) {
				continue;
			}

			if (isSmokersFree != room.isSmokersFree()) {
				continue;
			}
			return room;
		}
		System.out.println("Room not found");
		return null;
	}

	public void confirmReservation(Reservation reservation, Hotel hotel) {
		if (reservation.getRoom() == null) {
			System.out.println("Please add room to this reservation details");
			return;
		}
		setReservationStatus(ReservationStatusEnum.CONFIRMED_RESERVATION);
		hotel.addReservation(reservation);
	}

	@Override
	public String toString() {
		return "[Room type = " + roomType.getName() + ", hasBreakfast = " + hasBreakfast + ", hasDinner = " + hasDinner
				+ ", isSmokersFree = " + isSmokersFree + ", reservationStatus = " + reservationStatus + "]";
	}

}
